package com.itqf.mybatis;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.mapper.AuthorMapper;
import com.itqf.pojo.Author;
import com.itqf.utils.SqlSessionUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * projectName: mybatisgp8
 *
 * @author: 赵伟风
 * time: 2021/7/30 16:59
 * description:测试一级缓存
 */
public class UseIf {

    public static void main(String[] args) {

        /**
         *
         * mybatis的一级缓存是默认开启的!
         *   一个缓存的范围: 统一sqlSession对象[同一个SqlSession不同mapper]
         *
         *
         */

        SqlSession sqlSession = SqlSessionUtils.openSession();


        AuthorMapper mapper = sqlSession.getMapper(AuthorMapper.class);



        //1.设置分页属性[告诉分页插件limit]  limit 0,3;
        PageHelper.startPage(2, 4);

        List<Author> authors = mapper.queryByPage();

        //2.pageBean
        PageInfo<Author> pageInfo = new PageInfo<>(authors);

        /**
         * 1.当前页数
         * 2.总条数
         * 3.页容量
         * 4.总页数
         * 5.数据 List
         * 6.下一页
         * 7.上一页
         * 8.是否有下一页
         * 9.是否有上一页
         */

        /**
         * 当前页
         */
        int pageNum = pageInfo.getPageNum();
        System.out.println("pageNum = " + pageNum);

        /**
         * 总条数
         */
        long total = pageInfo.getTotal();
        System.out.println("total = " + total);

        /**
         * 当前页显示的数量
         */
        int size = pageInfo.getSize();
        System.out.println("size = " + size);

        /**
         * 总页数
         */
        int pages = pageInfo.getPages();
        System.out.println("pages = " + pages);


        /**
         * 数据
         */
        List<Author> list = pageInfo.getList();
        System.out.println("list = " + list);

        /**
         * 每页数量
         */
        int pageSize = pageInfo.getPageSize();
        System.out.println("pageSize = " + pageSize);


        sqlSession.close();


    }

}
